package app.util;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import app.handler.HelloHandler;

//A ContextHandler is a ScopedHandler that responds only to requests that have a URI prefix that matches the configured context path. Requests that match the context path have their path methods updated accordingly and the contexts scope is available, which optionally may include:
//A Classloader that is set as the Thread context classloader while request handling is in scope.
//A set of attributes that is available via the ServletContext API.
//A set of init parameters that is available via the ServletContext API.
//A base Resource which is used as the document root for static resource requests via the ServletContext API.
//A set of virtual host names.
//The following OneContext example shows a context being established that wraps the HelloHandler:


public class OneContext {
	
	public static void main(String[] args) throws Exception {
		Server server = new Server(8083);
		
		ContextHandler context = new ContextHandler();
		context.setContextPath("/hello");
		context.setHandler(new HelloHandler());
		
		server.setHandler(context);
		
		server.start();
		server.join();			//这是Thread的join方法，本意是等到这个阻塞，等到这个线程执行完毕才会执行后面的方法，这里start（）后面并无其他方法，所以不需要加，而且server的start永远不会执行完毕。
	}
}
